package com.lxw.nonghe.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lxw.nonghe.entity.OperationLog;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface OperationLogMapper extends BaseMapper<OperationLog> {

    @Select("SELECT username, module, operation, status, operation_time as operationTime " +
            "FROM t_operation_log " +
            "ORDER BY operation_time DESC " +
            "LIMIT 10")
    List<OperationLog> selectRecentLogs();

    @Select("SELECT username, module, operation, status, operation_time as operationTime " +
            "FROM t_operation_log " +
            "WHERE (#{username} IS NULL OR username LIKE CONCAT('%', #{username}, '%')) " +
            "AND (#{module} IS NULL OR module LIKE CONCAT('%', #{module}, '%')) " +
            "AND (#{status} IS NULL OR status = #{status}) " +
            "ORDER BY operation_time DESC")
    IPage<OperationLog> selectLogPage(Page<OperationLog> page,
                                      @Param("username") String username,
                                      @Param("module") String module,
                                      @Param("status") String status);
}
